/**
 * @author 35326
 * 2021/3/22 18:00
 * 内存可见性的测试
 */
class Test1 {

	public void incrise(int i){
		i=i++;
	}
	public static void main(String[] args) {
		MyThread myThread = new MyThread();
		myThread.start();
		while(true){
			if(myThread.isFlag()){
				System.out.println("主线程执行完毕……");
			}
		}
	}
}
class MyThread extends Thread{
	private boolean flag=false;

	@Override
	public void run() {
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		flag=true;
		System.out.println("分线程执行完了");

	}

	public boolean isFlag() {
		return flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}
}